class Solution:
    def lengthOfLIS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:return 0
        dp = [1]*len(nums)
        res = 1
        for i in range(len(nums)):
            for j in range(i):
                if nums[i] > nums[j]:
                    dp[i] = max(dp[i],dp[j] + 1)
            res = max(res,dp[i])
        return res


    def lengthOfLIS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if not nums:return 0
        res = [nums[0]]
        for i in range(1,len(nums)):
            if nums[i] > res[-1]:res.append(nums[i])
            else:
                l,r = 0,len(res)-1
                while l <= r:
                    mid = (l + r) // 2
                    if nums[i] > res[mid]:l = mid + 1
                    else:r = mid - 1
                res[l] = nums[i]# 如果比当前最大的小，那么找出它最适合的位置将值替换
            print(res)